{%- assign taboolaPixels = storeConfig.taboola | strtoarray -%}
{% assign adwords = storeConfig.google_adwords_trace_id | strtoarray %}
{% assign tracking = storeConfig.google_analytics_trace_id | strtoarray %}
{% assign conversion = storeConfig.google_conversion_id | strtoarray %}

{%- assign bigo_pixels = storeConfig.bigo_pixel_id | strtoarray -%}
{%- assign vk_pixels = storeConfig.vkontakte | strtoarray -%}
{%- assign yandex_pixels = storeConfig.yandex | strtoarray -%}
{%- assign outbrain_pixels = storeConfig.outbrain | strtoarray -%}
{%- assign criteo_pixels = storeConfig.criteo_pixel_id | strtoarray -%}


{%- assign yahoo_pixels = storeConfig.yahoo_pixel_id -%}


<script type="text/javascript">
function callback_add_to_cart(a){window.TOP_GLOBAL_CALLBACK_LAYER.on("add_to_cart")(a),window.moi&&moi.onEvent("callback_add_to_cart",a),console.log("callback_add_to_cart"),console.log(a);try{"function"==typeof callback_google_add_to_cart&&callback_google_add_to_cart(a),"function"==typeof callback_facebook_add_to_cart&&callback_facebook_add_to_cart(a),"function"==typeof callback_kwai_add_to_cart&&callback_kwai_add_to_cart(a),"function"==typeof callback_yahoo_add_to_cart&&callback_yahoo_add_to_cart(a),"function"==typeof callback_taboola_add_to_cart&&callback_taboola_add_to_cart(a),"function"==typeof callback_event_script_add_to_cart&&callback_event_script_add_to_cart(a),"function"==typeof callback_bigo_add_to_cart&&callback_bigo_add_to_cart(a),"function"==typeof callback_vk_add_to_cart&&callback_vk_add_to_cart(a),"function"==typeof callback_yandex_add_to_cart&&callback_yandex_add_to_cart(a),"function"==typeof callback_outbrain_add_to_cart&&callback_outbrain_add_to_cart(a),"function"==typeof callback_criteo_add_to_cart&&callback_criteo_add_to_cart(a)}catch(a){console.log(a)}}function callback_remove_from_cart(a){window.TOP_GLOBAL_CALLBACK_LAYER.on("remove_from_cart")(a),window.moi&&moi.onEvent("callback_remove_from_cart",a),console.log("callback_remove_from_cart"),console.log(a);try{"function"==typeof callback_google_remove_from_cart&&callback_google_remove_from_cart(a),"function"==typeof callback_facebook_remove_from_cart&&callback_facebook_remove_from_cart(a),"function"==typeof callback_kwai__remove_from_cart&&callback_kwai__remove_from_cart(a),"function"==typeof callback_yahoo_remove_from_cart&&callback_yahoo_remove_from_cart(a),"function"==typeof callback_event_script_remove_from_cart&&callback_event_script_remove_from_cart(a)}catch(a){console.log(a)}}function callback_login(){window.TOP_GLOBAL_CALLBACK_LAYER.on("login")(),window.moi&&moi.onEvent("callback_login"),console.log("callback_login");try{"function"==typeof callback_google_login&&callback_google_login(),"function"==typeof callback_facebook_login&&callback_facebook_login(),"function"==typeof callback_kwai_login&&callback_kwai_login(),"function"==typeof callback_yahoo_login&&callback_yahoo_login(),"function"==typeof callback_script_event_login&&callback_script_event_login()}catch(a){console.log(a)}}function callback_sign_up(){window.TOP_GLOBAL_CALLBACK_LAYER.on("sign_up")(),window.moi&&moi.onEvent("callback_sign_up"),console.log("callback_sign_up");try{"function"==typeof callback_google_sign_up&&callback_google_sign_up(),"function"==typeof callback_facebook_sign_up&&callback_facebook_sign_up(),"function"==typeof callback_kwai_sign_up&&callback_kwai_sign_up(),"function"==typeof callback_yahoo_sign_up&&callback_yahoo_sign_up(),"function"==typeof callback_taboola_sign_up&&callback_taboola_sign_up(),"function"==typeof callback_bigo_sign_up&&callback_bigo_sign_up(),"function"==typeof callback_vk_sign_up&&callback_vk_sign_up(),"function"==typeof callback_yandex_sign_up&&callback_yandex_sign_up(),"function"==typeof callback_event_script_sign_up&&callback_event_script_sign_up()}catch(a){console.log(a)}}function callback_share_product(a,o){window.TOP_GLOBAL_CALLBACK_LAYER.on("share_product")(a,o),window.moi&&moi.onEvent("callback_share_product",{ec_data:a,platform:o}),console.log("callback_share_product"),console.log(a),console.log(o);try{"function"==typeof callback_google_share_product&&callback_google_share_product(a,o),"function"==typeof callback_facebook_share_product&&callback_facebook_share_product(a,o),"function"==typeof callback_kwai_share_product&&callback_kwai_share_product(a,o),"function"==typeof callback_yahoo_share_product&&callback_yahoo_share_product(a,o),"function"==typeof callback_event_script_share_product&&callback_event_script_share_product(a,o),"function"==typeof callback_base_share_product&&callback_base_share_product(a,o)}catch(a){console.log(a)}}function callback_generate_lead(){window.TOP_GLOBAL_CALLBACK_LAYER.on("generate_lead")(),window.moi&&moi.onEvent("callback_generate_lead"),console.log("callback_generate_lead");try{"function"==typeof callback_google_generate_lead&&callback_google_generate_lead(),"function"==typeof callback_facebook_generate_lead&&callback_facebook_generate_lead(),"function"==typeof callback_kwai_generate_lead&&callback_kwai_generate_lead(),"function"==typeof callback_yahoo_generate_lead&&callback_yahoo_generate_lead(),"function"==typeof callback_event_script_generate_lead&&callback_event_script_generate_lead()}catch(a){console.log(a)}}function callback_begin_checkout(){window.TOP_GLOBAL_CALLBACK_LAYER.on("begin_checkout")(),window.moi&&moi.onEvent("callback_begin_checkout"),console.log("callback_begin_checkout");try{"function"==typeof callback_google_begin_checkout&&callback_google_begin_checkout(),"function"==typeof callback_facebook_begin_checkout&&callback_facebook_begin_checkout(),"function"==typeof callback_kwai_begin_checkout&&callback_kwai_begin_checkout(),"function"==typeof callback_yahoo_begin_checkout&&callback_yahoo_begin_checkout(),"function"==typeof callback_taboola_begin_checkout&&callback_taboola_begin_checkout(),"function"==typeof callback_bigo_begin_checkout&&callback_bigo_begin_checkout(),"function"==typeof callback_outbrain_begin_checkout&&callback_outbrain_begin_checkout(),"function"==typeof callback_event_script_begin_checkout&&callback_event_script_begin_checkout()}catch(a){console.log(a)}}function callback_add_address_information(){window.TOP_GLOBAL_CALLBACK_LAYER.on("add_address_information")(),window.moi&&moi.onEvent("callback_add_address_information"),console.log("callback_add_address_information");try{"function"==typeof callback_google_add_address_information&&callback_google_add_address_information(),"function"==typeof callback_facebook_add_address_information&&callback_facebook_add_address_information(),"function"==typeof callback_kwai_add_address_information&&callback_kwai_add_address_information(),"function"==typeof callback_yahoo_add_address_information&&callback_yahoo_add_address_information(),"function"==typeof callback_event_script_add_address_information&&callback_event_script_add_address_information()}catch(a){console.log(a)}}function callback_add_shipping_information(){window.TOP_GLOBAL_CALLBACK_LAYER.on("add_shipping_information")(),window.moi&&moi.onEvent("callback_add_shipping_information"),console.log("callback_add_shipping_information");try{"function"==typeof callback_google_add_shipping_information&&callback_google_add_shipping_information(),"function"==typeof callback_facebook_add_shipping_information&&callback_facebook_add_shipping_information(),"function"==typeof callback_kwai_add_shipping_information&&callback_kwai_add_shipping_information(),"function"==typeof callback_yahoo_add_shipping_information&&callback_yahoo_add_shipping_information(),"function"==typeof callback_event_script_add_shipping_information&&callback_event_script_add_shipping_information()}catch(a){console.log(a)}}function callback_add_payment_information(){window.TOP_GLOBAL_CALLBACK_LAYER.on("add_payment_information")(),window.moi&&moi.onEvent("callback_add_payment_information"),console.log("callback_add_payment_information");try{"function"==typeof callback_google_add_payment_information&&callback_google_add_payment_information(),"function"==typeof callback_facebook_add_payment_information&&callback_facebook_add_payment_information(),"function"==typeof callback_kwai_add_payment_information&&callback_kwai_add_payment_information(),"function"==typeof callback_yahoo_add_payment_information&&callback_yahoo_add_payment_information(),"function"==typeof callback_taboola_add_payment_information&&callback_taboola_add_payment_information(),"function"==typeof callback_event_script_add_payment_information&&callback_event_script_add_payment_information()}catch(a){console.log(a)}}function callback_add_to_wishlist(a){window.TOP_GLOBAL_CALLBACK_LAYER.on("add_to_wishlist")(a),window.moi&&moi.onEvent("callback_add_to_wishlist",a),console.log("callback_add_to_wishlist");try{"function"==typeof callback_google_to_wishlist&&callback_google_to_wishlist(a),"function"==typeof callback_facebook_to_wishlist&&callback_facebook_to_wishlist(a),"function"==typeof callback_kwai_to_wishlist&&callback_kwai_to_wishlist(a),"function"==typeof callback_vk_to_wishlist&&callback_vk_to_wishlist(a),"function"==typeof callback_yandex_to_wishlist&&callback_yandex_to_wishlist(a),"function"==typeof callback_taboola_to_wishlist&&callback_taboola_to_wishlist(a)}catch(a){console.log(a)}}function callback_place_an_order(a){window.TOP_GLOBAL_CALLBACK_LAYER.on("place_an_order")(a),"function"==typeof callback_event_script_place_an_order&&callback_event_script_place_an_order()}window.TOP_GLOBAL_CALLBACK_LAYER={on(a){const _=this;return function(...o){Array.isArray(_[a])&&_[a].forEach(a=>a.apply(this,o))}},add(a,o){this[a]||(this[a]=[]),this[a].push(o)},register(a){a&&"object"==typeof a&&Object.entries(a).forEach(([a,o])=>{this.add(a,o)})}};
</script>

{% include analysis_base %}

{%- if adwords or tracking or conversion -%}
{% include analysis_google %}
{%- endif -%}

{% include analysis_bing %}

{% include analysis_facebook %}

{% include analysis_pinterest %}

{% include analysis_snapchat %}


{% include analysis_tiktok %}


{%- if pixel_config.kwai_pixel_id == true -%}
{% include analysis_kwai %}
{%- endif -%}

{%- if pixel_config.yahoo_pixel == true -%}
{% include analysis_yahoo %}
{%- endif -%}


{%- if taboolaPixels -%}
{% include analysis_taboola %}
{%- endif -%}


{% if bigo_pixels %}
{% include "analysis_bigo",bigo_pixels:bigo_pixels %}
{% endif %}


{% if vk_pixels %}
    {% include "analysis_vk",vk_pixels:vk_pixels %}
{% endif %}
    
{% if yandex_pixels %}
    {% include "analysis_yandex",yandex_pixels:yandex_pixels %}
{% endif %}

{% if outbrain_pixels %}
    {% include "analysis_outbrain",outbrain_pixels:outbrain_pixels %}
{% endif %}

{% if criteo_pixels %}
    {% include "analysis_criteo",criteo_pixels:criteo_pixels %}
{% endif %}


{% include "analysis_twitter" %}
{% include "analysis_mediago" %}
{% include "analysis_newsbreak" %}
{% include "analysis_applovin" %}
{% include "analysis_smartnews" %}
{% include "analysis_reddit" %}
{% include "analysis_google_gtm" %}


{% include analysis_event_script %}

{% comment %}如果url有generate_lead参数  即代表有创建新用户{% endcomment %}
<script type="text/javascript">

document.addEventListener("DOMContentLoaded",function(){

    {%- if template == 'product_detail' -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('view_content')(_GET_C_SETTING_('product'));
    {%- elsif template == 'search_detail' -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('search')(`{{search.keywords | filter_string_format}}`,_GET_C_SETTING_("search_products"));
    {%- elsif template == 'collection_detail' -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('view_category')(_GET_C_SETTING_("collection"));
    {%- elsif template == 'cart_list' -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('cart_list')(_GET_C_SETTING_('cart'));
    {%- elsif controller == 'order' and action == 'success' -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('purchase')(_GET_C_SETTING_("order"));
    {%- elsif template == 'order_payment_gateway' and order.payment_type == 'offlinepay' and storeConfig.is_offlinepay_purchase_pixel == '1' -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('purchase')(_GET_C_SETTING_("order"));
    {%- else -%}
        window['TOP_GLOBAL_CALLBACK_LAYER'].on('page_view')();
    {%- endif -%}

    {% if current_step == 'contact_information' and template == 'order_contact_information' %}
    callback_begin_checkout();
    {% endif %}

    {% if template == 'orderonepage_index' %}
    callback_begin_checkout();
    document.addEventListener('onePageComplete',function(){
        callback_place_an_order()
    })
    {% endif %}

    {% if current_step == 'shipping_method' and template == 'order_shipping_method' %}
    callback_add_address_information();
    {% endif %}

    {% if current_step == 'payment_method' and template == 'order_payment_method' %}
    callback_add_shipping_information();
    {% endif %}

    {% if current_step == 'payment_gateway' and template == 'order_payment_gateway' %}
    // button event
    //callback_add_payment_information();
    {% endif %}

    {% if request_param.generate_lead %}
    callback_generate_lead();
    {% endif %}

    {% if controller == 'order' and action == 'checkout' and previous_step == 'shipping_method' and add_order == 1 %}
    callback_place_an_order()
    {% endif %}

})
</script>
